package com.example.demo.controller;

import com.example.demo.entity.Check.CheckDetailDTO;
import com.example.demo.service.CheckDetailService;
import com.example.demo.service.CheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/checkDetail")
public class CheckDetailController {

    @Autowired
    CheckDetailService checkDetailService;
    @Autowired
    CheckService checkService;

    @PostMapping("/findCheckDetailByBillNo")
    public List<CheckDetailDTO> findByBillNo (@RequestBody Map<String, String> payload) {
        String billNo = payload.get("billNo");
        System.out.println(billNo);
        List<CheckDetailDTO> checkDetailDTOs = checkDetailService.findByBillNo(billNo);
        for (int i = 0; i < checkDetailDTOs.size(); i++) {
            CheckDetailDTO checkDetailDTO = checkDetailDTOs.get(i);
            System.out.println(checkDetailDTO);
        }

        return checkDetailDTOs;

    }

    @PostMapping("/findCheckHeaderByBillNo")
    public Map<String,Object> findCheckHeaderByBillNo(@RequestBody Map<String, String> payload) {
        Map<String, Object> objectMap = checkService.find(payload);
        System.out.println(objectMap.toString());
        return objectMap;
    }

    @PostMapping("/findByGoodsCode")
    public List<CheckDetailDTO> findByGoodsCode(@RequestBody Map<String, String> param) {
        System.out.println("根据物料编号查询物料信息");
        System.out.println(param);
        List<CheckDetailDTO> checkDetailDTOS = checkDetailService.findByGoodsCode(param);
        for (int i = 0; i < checkDetailDTOS.size(); i++) {
            System.out.println(checkDetailDTOS.get(i));
        }
        return checkDetailDTOS;
    }

    @PostMapping("/add")
    public Map<String,Object> add(@RequestBody Map<String, Object> param) {
        System.out.println("添加盘点单");
        Map<String, Object> map = checkService.add(param);
        return map;
    }

    @PostMapping("/check")
    public Map<String,String> check(@RequestBody Map<String, String> param) {
        Map<String, String> check = checkService.check(param);
        return check;
    }

}
